
//
//  WebViewController.m
//  yilutongxing
//
//  Created by ios-21 on 17/4/18.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "WebViewController.h"

@interface WebViewController ()<UIWebViewDelegate>
@property (nonatomic ,strong)UIWebView *webV;
@property (nonatomic,copy)NSString *urlStr;
@end

@implementation WebViewController
-(UIWebView*)webV{
    if (!_webV) {
        UIWebView * webV1 = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
        webV1.delegate = self;
        webV1.backgroundColor = [UIColor whiteColor];
        [webV1 loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.yzjjh.org/"]]];
        [self.view addSubview:webV1];
        self.webV = webV1;
    }
    return _webV;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.tabBarController.tabBar.hidden = YES;
    self.title = @"了解基金会";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackGroundImage"] forBarMetrics:UIBarMetricsDefault];
    self.navigationItem.hidesBackButton = YES;
    
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStyleDone target:self action:@selector(goBackAction)];
    
    [self initRefersh];
}

- (void)goBackAction {
    [self.webV goBack];
    if (!self.webV.canGoBack) {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)initRefersh{

    self.webV.scrollView.mj_header=[RefershHelper headerWithRefreshingBlock:^{

        [self.webV loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.webV.request.URL.absoluteString]]];
         NSLog(@"下拉刷新self.webV.request.URL.absoluteString = %@",self.webV.request.URL.absoluteString);
        [self.webV.scrollView.mj_header endRefreshing];
    }];
    
}
#pragma mark - UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationTyp{
    
    return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView{
    self.urlStr = webView.request.URL.absoluteString;
    [UIApplication sharedApplication].networkActivityIndicatorVisible = YES;

}
- (void)webViewDidFinishLoad:(UIWebView *)webView{
    [self.webV.scrollView.mj_header endRefreshing];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
     NSLog(@"错误 %@",error);
    [self.webV.scrollView.mj_header endRefreshing];
}
@end
